﻿using System;
using System.Collections.Generic;
using System.Linq;
using Zero.POCO.FiltreEnumeration;
using Zero.POCO.Interfaces;

namespace Zero.POCO
{
    public static class FiltreFactory
    {
        static List<int> _premier = new List<int>() { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
        public static Filter CreateFiltre(IFiltre filtre   )
        {
            var _filtre = new Filter
                {
                    Nom = filtre.Nom,
                    Habitats = filtre.Habitats,
                    ageMax = filtre.ageMax,
                    ageMin = filtre.ageMin,
                    CSEs = filtre.CSEs,
                    CSPs = filtre.CSPs,
                    Equipements = filtre.Equipements,
                    Genres = filtre.Genres,
                    NbChambres = filtre.NbChambres,
                    NbVoitures = filtre.NbVoitures,
                    NiveauxInstructions = filtre.NiveauxInstructions,
                    RevenueTotalFoyers = filtre.RevenueTotalFoyers,
                    SituationMatrimonials = filtre.SituationMatrimonials,
                    StatutFamiliales = filtre.StatutFamiliales,
                    TailleFoyers = filtre.TailleFoyers,
                    TypeHabitations = filtre.TypeHabitations
                };

            return _filtre;
        }


        public static Boolean DesassembleFiltre(int listeEquipement, int prem)
        {
            if (listeEquipement == 1) return false;
            if (prem > listeEquipement)
            {
                return true;
            }
            return listeEquipement % prem == 0;
        }

        public static int AssembleFiltre(List<int> entite)
        {
            var resultat = entite.Select((t, i) => t*_premier[i]).Where(temp => temp != 0).Aggregate(1, (current, temp) => current*temp);
            return resultat;
        }
    }
}